package com.example.human_resource_management.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.human_resource_management.entry.dto.ResourceDto;
import com.example.human_resource_management.entry.po.Resource;
import com.example.human_resource_management.mapper.EmployeeMapper;
import com.example.human_resource_management.service.ResourceService;
import com.example.human_resource_management.mapper.ResourceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
* @author Lenovo
* @description 针对表【resource(资源表)】的数据库操作Service实现
* @createDate 2025-06-09 16:40:21
*/
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource>
    implements ResourceService{

    @Autowired
    private ResourceMapper resourceMapper;
    @Autowired
    private EmployeeMapper employeeMapper;


    @Override
    public List<ResourceDto> selectResourceListByEmpId(Long empId) {
            Long deptId = employeeMapper.getDeptIdByEmpId(empId);
        if (deptId == null) {
            return Collections.emptyList();
        }
        return resourceMapper.selectResourcesByDeptId(deptId);
    }
//管理员端
    @Override
    public List<ResourceDto> selectAllResources() {
        return resourceMapper.selectAllResources();
    }

    @Override
    public boolean addResource(Resource resource) {
        return save(resource);
    }

    @Override
    public boolean updateResource(Resource resource) {
        return updateById(resource);
    }

    @Override
    public boolean deleteResource(Long resId) {
        return removeById(resId);
    }
}




